package test;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;


public class ExcelDemo {
	public static void main(String[] args) {
		Workbook wb = new HSSFWorkbook();
		Sheet sheet1 = wb.createSheet("new sheet");//创建一个sheet    
		//HSSFSheet sheet2 = wb.createSheet("second sheet");//创建一个sheet    
		Row row =  sheet1.createRow(0);
		 //创建一个单元格，并在其中加入内容. 
		Cell cell = row.createCell((short) 1); 
	    cell.setCellValue(4); 
	 
	    //设置单元格边框为四周环绕. 
	    CellStyle style = wb.createCellStyle(); 
	    style.setBorderBottom(HSSFCellStyle.BORDER_THIN); 
	    style.setBottomBorderColor(IndexedColors.BLACK.getIndex()); 
	    style.setBorderLeft(HSSFCellStyle.BORDER_THIN); 
	    style.setLeftBorderColor(IndexedColors.GREEN.getIndex()); 
	    style.setBorderRight(HSSFCellStyle.BORDER_THIN); 
	    style.setRightBorderColor(IndexedColors.BLUE.getIndex()); 
	    style.setBorderTop(HSSFCellStyle.BORDER_MEDIUM_DASHED); 
	    style.setTopBorderColor(IndexedColors.BLACK.getIndex()); 
	    cell.setCellStyle(style); 
	 
	    //将输出流写入一个文件 
		FileOutputStream fileOut;
		try {
			fileOut = new FileOutputStream("D:\\cc.xls");
			wb.write(fileOut);
			fileOut.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}    
	
		
	}
}
